﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using Hongsh.Pay.Client.Proxy.Ssl;

namespace Hongsh.Pay.Client.Proxy.Http {
    // Token: 0x0200002A RID: 42
    public class HttpRequest : HttpStream {
        // Token: 0x1700007B RID: 123
        // (get) Token: 0x06000130 RID: 304 RVA: 0x00002D04 File Offset: 0x00000F04
        // (set) Token: 0x06000131 RID: 305 RVA: 0x00002D11 File Offset: 0x00000F11
        public bool KeepAlive {
            get => Header.KeepAlive;
            set => Header.KeepAlive = value;
        }

        // Token: 0x1700007C RID: 124
        // (get) Token: 0x06000132 RID: 306 RVA: 0x00002D1F File Offset: 0x00000F1F
        public HttpConnection Connection { get; }

        // Token: 0x1700007D RID: 125
        // (get) Token: 0x06000133 RID: 307 RVA: 0x00002D27 File Offset: 0x00000F27
        public HttpRequestHeader Header { get; }

        // Token: 0x1700007E RID: 126
        // (get) Token: 0x06000134 RID: 308 RVA: 0x00002D2F File Offset: 0x00000F2F
        public Uri Url { get; }

        // Token: 0x1700007F RID: 127
        // (get) Token: 0x06000135 RID: 309 RVA: 0x00002D37 File Offset: 0x00000F37
        public string Method {
            get {
                return Header.Method;
            }
        }

        // Token: 0x17000080 RID: 128
        // (get) Token: 0x06000136 RID: 310 RVA: 0x00002D44 File Offset: 0x00000F44
        public string Version {
            get {
                return Header.Version;
            }
        }

        // Token: 0x17000081 RID: 129
        // (get) Token: 0x06000137 RID: 311 RVA: 0x0000B878 File Offset: 0x00009A78
        public Dictionary<string, string> Form {
            get {
                if (_Form == null) {
                    _Form = new Dictionary<string, string>();
                    try {
                        string str = new StreamReader(this).ReadToEnd();
                        string[] array = HttpUtility.UrlDecode(str).Split(new char[]
                        {
                            '&'
                        }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string text in array) {
                            string[] array3 = text.Split(new char[]
                            {
                                '='
                            }, 2);
                            _Form[array3[0]] = (array3.Length > 1) ? array3[1] : null;
                        }
                    }
                    catch {
                    }
                }
                return _Form;
            }
        }

        // Token: 0x17000082 RID: 130
        // (get) Token: 0x06000138 RID: 312 RVA: 0x0000B928 File Offset: 0x00009B28
        public Dictionary<string, string> UrlForm {
            get {
                if (_UrlForm == null) {
                    _UrlForm = new Dictionary<string, string>();
                    string[] array = HttpUtility.UrlDecode(Url.Query).TrimStart(new char[]
                    {
                        '?'
                    }).Split(new char[]
                    {
                        '&'
                    }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string text in array) {
                        string[] array3 = text.Split(new char[]
                        {
                            '='
                        }, 2);
                        _UrlForm[array3[0]] = (array3.Length == 2) ? array3[1] : null;
                    }
                }
                return _UrlForm;
            }
        }

        // Token: 0x06000139 RID: 313 RVA: 0x0000B9D0 File Offset: 0x00009BD0
        public HttpRequest(HttpConnection conn, HttpRequestHeader header, Stream input_stream) : base(input_stream) {
            //Class15.cwcZ3SWztHroi();
            _Form = null;
            _UrlForm = null;
            //base..ctor(input_stream);
            Connection = conn;
            Header = header;
            string scheme = (Connection.SocketStream is SSLStream) ? "https" : "http";
            string[] array = Header.Host.Split(new char[]
            {
                ':'
            }, 2);
            int portNumber = (array.Length == 2) ? int.Parse(array[1]) : Connection.LocalEndPoint.Port;
            Url = new Uri(new UriBuilder(scheme, array[0], portNumber).Uri, Header.Path);
        }

        // Token: 0x17000083 RID: 131
        // (get) Token: 0x0600013A RID: 314 RVA: 0x00002D51 File Offset: 0x00000F51
        public override bool CanRead {
            get {
                return BaseStream.CanRead;
            }
        }

        // Token: 0x17000084 RID: 132
        // (get) Token: 0x0600013B RID: 315 RVA: 0x00002A36 File Offset: 0x00000C36
        public override bool CanWrite {
            get {
                return false;
            }
        }

        // Token: 0x0600013C RID: 316 RVA: 0x00002A4F File Offset: 0x00000C4F
        public override void Flush() {
            throw new NotImplementedException();
        }

        // Token: 0x0600013D RID: 317 RVA: 0x0000BA88 File Offset: 0x00009C88
        public override int Read(byte[] buffer, int offset, int count) {
            return BaseStream.Read(buffer, offset, count);
        }

        // Token: 0x0600013E RID: 318 RVA: 0x00002A4F File Offset: 0x00000C4F
        public override void Write(byte[] buffer, int offset, int count) {
            throw new NotImplementedException();
        }

        // Token: 0x0400008D RID: 141
        private Dictionary<string, string> _Form;

        // Token: 0x0400008E RID: 142
        private Dictionary<string, string> _UrlForm;
    }
}
